<?php
declare (strict_types=1);

namespace app\admin\controller;

use app\common\builder\TableBuilder;
use app\common\builder\TableFront;
use think\App;

class ProductSearchLog extends Base
{
    //主键，默认为id
    protected $pk = 'id';

    //主模型
    protected $model = '\app\common\model\ProductSearchLog';

    protected $hasOne = ['user'];

    protected $append = ['area'];

    public function index()
    {
        return $this->setTable();
    }

    public function setTable()
    {
        //构建table
        $tableFront = TableFront::getInstance()
            ->addRow(['field' => 'id', 'title' => 'ID', 'sort' => true, 'width' => 80])
            ->addRow(['field' => 'keyword', 'title' => '搜索关键字', 'format' => 'input', 'modify' => 'add|edit'])
            ->addRow(['field' => 'nickname', 'title' => '会员昵称', 'width' => 100, 'templet' => '<div>{{d.user?d.user.nickname:""}}</div>'])
            ->addRow(['field' => 'code', 'title' => '会员编号', 'width' => 100, 'templet' => '<div>{{d.user?d.user.code:""}}</div>'])
            ->addRow(['field' => 'mobile', 'title' => '会员手机号', 'width' => 200, 'templet' => '<div>{{d.user?d.user.mobile:""}}</div>'])
            ->addRow(['field' => 'area', 'title' => '所在地区', 'width' => 200])
            ->addRow(['field' => 'create_time', 'title' => '搜索时间', 'width' => 200])
            ->addRow(['fixed' => 'right', 'align' => 'center', 'toolbar' => '#rightBtn', 'title' => '操作', 'width' => 150])
            ->clearTable();

        return TableBuilder::getInstance()
            ->addColumns($tableFront)
            ->setSearch($this->setSearch())
            ->fetch();
    }

    public function setSearch()
    {
        return TableFront::getInstance()
            ->setSearch(['keyword', '关键字', 'input', '', '', '', 'like']);
    }
}
